package com.example.oasystem.dao.note;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.oasystem.entity.attachment.AoaAttachmentListOfJian;
import com.example.oasystem.entity.daymanage.EmpDTO;
import com.example.oasystem.entity.note.AoaCatalog;
import com.example.oasystem.entity.note.AoaNoteList;
import com.example.oasystem.entity.note.AoaReceiverNote;
import com.example.oasystem.entity.process.AoaAttachmentList;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.type.AoaTypeList;
import com.example.oasystem.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface AoaNoteListDao extends BaseMapper<AoaNoteList> {
    //查询所有的目录
    @Select("select * from aoa_catalog where cata_user_id=#{id}")
    List<AoaCatalog> catalogList(Long id);

    //查出所有的note
    List<AoaNoteList> noteList(int id,int cid,int typeId);
    List<AoaNoteList> noteListByText(@Param("text") String text,int id,int cid,int typeId);
    //查询所有的类型
    @Select("select * from aoa_type_list where type_model='aoa_note_list'")
    List<AoaTypeList> findType();
    //查出所有的状态
    @Select("select * from aoa_status_list where status_model='aoa_note_list'")
    List<AoaStatusList> findStatus();

    List<EmpDTO> getAllEmps();

    @Select("select * from aoa_note_list where note_id=#{id}")
    AoaNoteList selectOneOfNote(int id);
    //根据目录主键查寻整个对象
    @Select("select * from aoa_catalog where catalog_id=#{cid}")
    AoaCatalog selectOneCatalog(int cid);

    int insertNote(AoaNoteList noteList);
    //插入receviernote记录
    @Insert("insert into aoa_receiver_note(note_id,user_id) values(#{noteId},#{userId})")
    int insertReceiveNote(AoaReceiverNote receiverNote);
    @Select("select * from aoa_user where user_name=#{userName}")
    AoaUser selectOneOfUser(String userName);
    @Select("select * from aoa_user where user_id=#{id}")
    AoaUser selectOneOfUserId(Long id);
    @Update("update aoa_note_list set content=#{content},status_id=#{statusId},title=#{title},type_id=#{typeId},catalog_id=#{catalogId},attach_id=#{attachId},receiver=#{receiver} where note_id=#{noteId}")
    int updateNoteList(AoaNoteList noteList);

    @Select("select *from aoa_attachment_list where attachment_id=#{id}")
    AoaAttachmentListOfJian selectAttachment(Long id);

    @Delete("delete  from  aoa_receiver_note where note_id=#{id}")
    int deletReceiverNote(Long id);
    //根据id查找附件
    @Select("select * from aoa_attachment_list where attachment_id=#{aid}")
    AoaAttachmentList selectOneAttach(Long aid);
    //插入新增目录
    @Insert("insert into aoa_catalog(catalog_name,parent_id,cata_user_id) values(#{name},#{id},#{uid})")
    int insertcatalog(String name,int id,Long uid);
    //根据noteid查找receivernote
    @Delete("delete from aoa_receiver_note where note_id=#{noteId}")
    int deleteByNoteId(int noteId);
    //根据附件id删除附件
    @Delete("delete from aoa_attachment_list where attachment_id=#{aid}")
    int deleteAttach(Long aid);
    @Delete("delete from aoa_note_list where note_id=#{nid}")
    int deleteNoteList(int nid);
    //根据noteId删除note
    @Delete("delete from aoa_note_list where note_id=#{noteId}")
    int deleteNoteByNoteId(int noteId);

    //查出所有的cid下的note
    @Select("select * from aoa_note_list where catalog_id=#{cid}")
    List<AoaNoteList> findByCid(int cid);
    //根据目录id删除note
    @Delete("delete from aoa_note_list where catalog_id=#{cid}")
    int deleteNoteByCid(int cid);
    //删除目录
    @Delete("delete from aoa_catalog where catalog_id=#{cid}")
    int deleteCatalog(int cid);
    @Update("update aoa_note_list set is_collected=#{iscollected} where note_id=#{id}")
    int updateIsCollect(int id,int iscollected);


}